package Operation;

import Book.Book;
import Book.BookList;

import java.util.Scanner;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User:岁亮亮
 * Date:2024-01-14
 * TIME:15:25
 */
public class del implements Iooperation{
    @Override
    public void work(BookList bookList) {
        System.out.println("删除图书");
        System.out.println("请输入你要删除图书的书名");
        Scanner scanner=new Scanner(System.in);
        String str=scanner.nextLine();
        int ret=bookList.getUsesize();
        int flag=1;
        for (int i = 0; i < ret; i++) {
            if(str.equals(bookList.getbooks(i) .getName())){
                for (int j = i; j < ret-1; j++) {
                   Book book= bookList .getbooks(j+1);
                   bookList .setbooks(book,j);
                   flag=-1;
                }
            }
        }
        if(flag==1){
            System.out.println("书架上没有你要删除的图书");
        }
        else {
            ret--;
            bookList.setUsesize(ret);
            System.out.println("删除成功");
        }
    }
}
